/*
 * Copyright (c) 2020, 2025, keyila All rights reserved.
 *
 */
package com.clp.study.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clp.entity.PageResult;
import com.clp.study.entity.dto.UserDto;
import com.clp.study.entity.po.UserPo;
import com.clp.study.mapper.UMapper;
import com.clp.study.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author clp
 * @version 1.0
 */
@Service
public class UserImpl implements UserService {

    @Autowired
    private UMapper userMapper;

    @Override
    public int addOne(UserDto userDto) {
        UserPo userPo=new UserPo();
        BeanUtils.copyProperties(userDto,userPo);
        int count = userMapper.insert(userPo);
        return count;
    }

    @Override
    public int deleteOneUser(Integer id) {
        return userMapper.deleteById(id);
    }

    @Override
    public PageResult<UserPo> getUserPage(UserDto userDto) {
        IPage<UserPo> userPoIPage=new Page<>(userDto.getPageIndex(),userDto.getPageSize());
        IPage<UserPo> userPage = userMapper.getUserPo(userPoIPage);
        PageResult<UserPo> pageResult=new PageResult<>();
        pageResult.loadDate(userPage);
        return pageResult;
    }
}
